//
//  CollectDetailsViewController.m
//  BeautifulShoppings
//
//  Created by GivenBmli on 16/9/14.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "CollectDetailsViewController.h"
#import "GuideHomeCollectionViewCell.h"
#import "NetworkHandler.h"
#import "UIImageView+WebCache.h"
#import "TAMacro.h"

@interface CollectDetailsViewController ()<UIScrollViewDelegate>
@property (nonatomic ,strong)UIWebView *webView;
@property (nonatomic ,strong)UIImageView * imageView;
@property (nonatomic ,strong)UIScrollView * scrollView;
@end
@implementation CollectDetailsViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *butt = [UIButton buttonWithType:UIButtonTypeCustom];
    [butt setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    butt.frame  = CGRectMake(0, 0, 50, 50);
    UIBarButtonItem *left= [[UIBarButtonItem alloc]initWithCustomView:butt];
    [butt addTarget:self action:@selector(clickLeft:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem =left;
    [self foundImageView];
    [self foundWebViwe];
}
// 攻略收藏 
- (void)foundWebViwe {
    self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [NetworkHandler getDataByURLString:[NSString stringWithFormat:@"http://api.liwushuo.com/v2/posts/%@?show_baichuan=0",self.str] BodyString:nil WithDataBlock:^(id result) {
        NSDictionary *dic = [result objectForKey:@"data"];
        self.image = [dic objectForKey:@"cover_image_url"];
        self.str2 = [dic objectForKey:@"content_html"];
        [self.webView  loadHTMLString:self.str2 baseURL:[NSURL fileURLWithPath: [[NSBundle mainBundle]  bundlePath]]];
        [self.view addSubview:self.webView];
        [self foundImageView];
        
    }];
}
- (void)foundImageView {
    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -SCREEN_HEIGHT / 3, SCREEN_WIDTH, SCREEN_HEIGHT / 3)];
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:self.image] placeholderImage:[UIImage imageNamed:@"站位"]];
    self.webView.scrollView.contentInset = UIEdgeInsetsMake(SCREEN_HEIGHT / 3, 0, 0, 0 );
    [self.webView.scrollView addSubview:self.imageView];
}
- (void)clickLeft:(UIButton *)qwe {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
